package tech.aistar.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tech.aistar.pojo.User;
import tech.aistar.pojo.UserInfo;
import tech.aistar.pojo.vo.UserInfoVo;

@Mapper
public interface UserInfoMapper {

        /**
         * 根据用户id来返回单个用户,因为id是唯一的
         * @param id 用户的id
         * @return 单个用户
         */
        //查询，根据用户id：user_id
        @Select("select * from user_info where user_id=#{userId}")
        User selectById(int userId );


        //修改，根据用户id：user_id
        @Update("update user_info set sex=#{sex},address=#{address},introduction=#{introduction} where user_id=#{userId}")
        int updateById(UserInfo user);

        //增加
        @Insert("insert into user_info(user_id,sex,address,introduction) values(#{userId},#{sex},#{address},#{introduction})")
        int add(UserInfo user);

        //根据email查用户
        @Select("select * from user where email=#{email}")
        User selectByEmail(String email );

        //根据email改密码
        @Update("update user set password=#{password} where email=#{email}")
        int updatePwdByEmail(User user);

        //根据user_id改名字/手机号/生日/性别
        @Update("update user set username=#{username},phone=#{phone} where user_id=#{userId}")
        int updateUserByUser_id(User user);
        //根据user_id改/性别
        @Update("update user_info set sex=#{sex},address=#{address},introduction=#{introduction} where user_id=#{userId}")
        int updateInfoByUser_id(UserInfo user);

        //跟据user_id 查user和user_info表的信息
        @Select("select *  from user  left join  user_info on user.user_id=user_info.user_id where user.user_id=#{userId}")
        UserInfoVo selectInfoByUser_id(int userId);




}
